<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><%= title %></title>
    <link rel='stylesheet' href='css/style.css' />
    <link rel="stylesheet" href="css/loginreg.css">
    <script src="js/jquery.js" type="text/javascript"></script>
</head>

<body>
<div id="wrapper">
    <ul class="bg-bubbles">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
<div id="container" class="container">
    <% if (locals.success) { %>
    <div id="alt_sucess" style="text-align:center">
        <%- success %>
    </div>
    <% } %>

    <% if (locals.error) { %>
    <div id="alt_warning" style="text-align:center">
        <%= error %>
    </div>
    <% } %>

    <% if(locals.islogin){ %>
    用户已登录，<%= locals.islogin %> <a href="/logout">退出</a><br>
    <a href="/blog?nav=index">返回首页</a>
    <% } else { %>
    <form class="login-form" role="form" method="post">
        <h1>登录</h1>
        <div class="flex-row">
            <label class="lf--label" for="txtUserName">
                <svg x="0px" y="0px" width="12px" height="13px">
                    <path fill="#B1B7C4" d="M8.9,7.2C9,6.9,9,6.7,9,6.5v-4C9,1.1,7.9,0,6.5,0h-1C4.1,0,3,1.1,3,2.5v4c0,0.2,0,0.4,0.1,0.7 C1.3,7.8,0,9.5,0,11.5V13h12v-1.5C12,9.5,10.7,7.8,8.9,7.2z M4,2.5C4,1.7,4.7,1,5.5,1h1C7.3,1,8,1.7,8,2.5v4c0,0.2,0,0.4-0.1,0.6 l0.1,0L7.9,7.3C7.6,7.8,7.1,8.2,6.5,8.2h-1c-0.6,0-1.1-0.4-1.4-0.9L4.1,7.1l0.1,0C4,6.9,4,6.7,4,6.5V2.5z M11,12H1v-0.5 c0-1.6,1-2.9,2.4-3.4c0.5,0.7,1.2,1.1,2.1,1.1h1c0.8,0,1.6-0.4,2.1-1.1C10,8.5,11,9.9,11,11.5V12z"/>
                </svg>
            </label>
            <input id="txtUserName" name="txtUserName" type="text" class="lf--input" placeholder="用户名" required autofocus />
        </div>
        <div class="flex-row">
            <label class="lf--label" for="txtUserPwd">
                <svg x="0px" y="0px" width="15px" height="5px">
                    <g>
                        <path fill="#B1B7C4" d="M6,2L6,2c0-1.1-1-2-2.1-2H2.1C1,0,0,0.9,0,2.1v0.8C0,4.1,1,5,2.1,5h1.7C5,5,6,4.1,6,2.9V3h5v1h1V3h1v2h1V3h1 V2H6z M5.1,2.9c0,0.7-0.6,1.2-1.3,1.2H2.1c-0.7,0-1.3-0.6-1.3-1.2V2.1c0-0.7,0.6-1.2,1.3-1.2h1.7c0.7,0,1.3,0.6,1.3,1.2V2.9z"/>
                    </g>
                </svg>
            </label>
            <input id="txtUserPwd" name="txtUserPwd" type="password" class="lf--input" placeholder="密码" required/>
        </div>
        <div class="flex-row">
            <button id="btnSub" class="lf--submit" type="submit">登  录</button>
        </div>
        <div class="flex-row bot">
            <label class="checkbox">
                <input name="chbRem" id="chbRem" type="checkbox" value="remember-me"> 7天内免登录
            </label>
        </div>
        <div class="bot">还没有账号？请点击
            <a style="" href="/reg" role="button">注册</a>
        </div>

    </form>
    <% } %>
</div>
</body>
</html>
<script type="text/javascript">
    $(function(){
        $('#btnSub').on('click',function(){
            var
                $txtUserName = $('#txtUserName'),
                txtUserNameVal = $.trim($txtUserName.val()),
                $txtUserPwd = $('#txtUserPwd'),
                txtUserPwdVal = $.trim($txtUserPwd.val()),
                errorTip = '<div id="errorTip" class="alert alert-warning">{0}</div> ';

            $("#errorTip,#alt_warning").remove();

            if(txtUserNameVal.length == 0)
            {
                $("#container").prepend(errorTip.format('用户名不能为空'));
                $txtUserName.focus();
                return false;
            }

            if(txtUserPwdVal.length == 0)
            {
                $("#container").prepend(errorTip.format('密码不能为空'));
                $txtUserPwd.focus();
                return false;
            }

            return true;
        })
    });
</script>